package com.briup.ch13;

import com.sun.deploy.panel.ITreeNode;

import java.util.List;

/**
 * @Author briup-adam
 * @Date 2023/10/30 上午10:08
 * @Description 获取字节码对象
 *
 **/

public class ClassTest {
    public static void main(String[] args) {
        //类型名称后面接.class
        Class<int[][]> aClass = int[][].class;
        Class<Integer> bClass = int.class;
        Class<String> cClass = String.class;
        Class<List> dClass = List.class;
        System.out.println(aClass);
        System.out.println(bClass);
        System.out.println(cClass);
        System.out.println(dClass);
        //第二种  通过Class类中的静态方法 forName 只适用引用数据类型
        try {
            Class<?> eClass = Class.forName("[[I");
//            Class<?> fClass = Class.forName("int");
            Class<?> gClass = Class.forName("java.lang.String");
            Class<?> hClass = Class.forName("java.util.List");
            System.out.println(eClass);
            System.out.println(gClass);
            System.out.println(hClass);
            System.out.println(eClass==aClass);//true
            System.out.println(gClass==cClass);//true
            System.out.println(hClass==dClass);//true
//            System.out.println(fClass);
            //第三种只适合对象  通过getClass()方法  引用类型中接口不适合
            Class<? extends String> iClass = "s".getClass();
            Class<? extends int[][]> jClass = new int[2][].getClass();
            System.out.println(iClass);
            System.out.println(jClass);
            System.out.println(iClass==gClass);//true
            System.out.println(eClass==jClass);//true
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}
